/************************************************************************

								Heroes IV
					  Copyright 2002, The 3DO Company

	------------------------------------------------------------------
  					 combat_non_blocking_message_displayer.cpp

	$Header:  $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "combat_non_blocking_message_displayer.h"

#include <assert.h>
#include "options.h"


// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
t_combat_non_blocking_message_displayer::t_combat_non_blocking_message_displayer( t_battlefield & battlefield )
	: t_combat_action_message_displayer( battlefield ),
	  t_idle_processor( 1 ), // Start "off"
	  m_active( false )
{
}

// ----------------------------------------------------------------------
// Display message for display_time milliseconds. Note that display_time 
// is scaled by the current animation speed. 
// ----------------------------------------------------------------------
void t_combat_non_blocking_message_displayer::display_action_message( t_combat_action_message const & message, t_uint32 display_time )
{
	if ( m_active && get_action_message().get_priority() < message.get_priority() )
		return;

	t_combat_action_message_displayer::display_action_message( message );

	set_delay( display_time * 100 / get_combat_animation_speed() );

	if ( !m_active )
	{
		resume_idle_processing();
		m_active = true;
	}
}

// ----------------------------------------------------------------------
// Erase message
// ----------------------------------------------------------------------
void t_combat_non_blocking_message_displayer::erase_action_message()
{
	suspend_idle_processing();
	m_active = false;
	t_combat_action_message_displayer::erase_action_message();
}

// ----------------------------------------------------------------------
// Time is up, erase message
// ----------------------------------------------------------------------
void t_combat_non_blocking_message_displayer::on_idle()
{
	assert( m_active );
	erase_action_message();
}
